package com.atguigu2.two;

/**
 * @author lhl
 * @date 2025/3/27 11:50
 */
public class TwoArrayTest {

    public static void main(String[] args) {
        //1、数组的声明与初始化
        //1.1静态初始化
        int[][] arr2 = new int[][]{{1,2,3},{4,5},{6,7,8,9}};
        //1.2动态初始化1
        int[][] arr3 = new int[2][4];

        //动态初始化1
        double[][] arr4 = new double[3][];

        //其他方式
        int arr5[][] = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        int[] arr6[] = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        int arr7[][] = {{1,2,3},{4,5,6},{7,8,9}};


        //2、数组元素的调用
        //调用内存元素
        System.out.println(arr2[0][0]);

        //调用外层元素
        System.out.println(arr2[0]);//地址值

        arr4[0] = new double[4];
        arr4[0][0] = 1.0;

        //3.数组的长度
        System.out.println(arr2.length);
        System.out.println(arr2[2].length);


        //4，如何遍历数组
        for (int i = 0; i < arr2.length; i++) {
            for (int j = 0; j < arr2[i].length; j++) {
                System.out.print(arr2[i][j]);
            }
            System.out.println();
        }
    }
}
